﻿using System.Collections.Generic;
using System.Security.AccessControl;
using System.Linq;

namespace System.IO
{
    public class DefaultDirectoryInfo : DefaultFileSystemInfo, IDirectoryInfo
    {
        private readonly DirectoryInfo _directoryInfo;

        public DefaultDirectoryInfo(DirectoryInfo directoryInfo) 
            :base(directoryInfo)
        {
            _directoryInfo = directoryInfo;
        }

        public IDirectoryInfo CreateSubdirectory(string path)
        {
            return new DefaultDirectoryInfo(_directoryInfo.CreateSubdirectory(path));
        }

        public IDirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity)
        {
            return new DefaultDirectoryInfo(_directoryInfo.CreateSubdirectory(path, directorySecurity));
        }

        public void Create()
        {
            _directoryInfo.Create();
        }

        public void Create(DirectorySecurity directorySecurity)
        {
            _directoryInfo.Create(directorySecurity);
        }

        public DirectorySecurity GetAccessControl()
        {
            return _directoryInfo.GetAccessControl();
        }

        public DirectorySecurity GetAccessControl(AccessControlSections includeSections)
        {
            return _directoryInfo.GetAccessControl(includeSections);
        }

        public void SetAccessControl(DirectorySecurity directorySecurity)
        {
            _directoryInfo.SetAccessControl(directorySecurity);
        }

        public IFileInfo[] GetFiles(string searchPattern)
        {
            return _directoryInfo.GetFiles(searchPattern).Select(t => new DefaultFileInfo(t)).Cast<IFileInfo>().ToArray();
        }

        public IFileInfo[] GetFiles(string searchPattern, SearchOption searchOption)
        {
            return _directoryInfo.GetFiles(searchPattern, searchOption).Select(t => new DefaultFileInfo(t)).Cast<IFileInfo>().ToArray();
        }

        public IFileInfo[] GetFiles()
        {
            return _directoryInfo.GetFiles().Select(t => new DefaultFileInfo(t)).Cast<IFileInfo>().ToArray();
        }

        public IDirectoryInfo[] GetDirectories()
        {
            return _directoryInfo.GetDirectories().Select(t => new DefaultDirectoryInfo(t)).Cast<IDirectoryInfo>().ToArray();
        }

        public IFileSystemInfo[] GetFileSystemInfos(string searchPattern)
        {
            return _directoryInfo.GetFileSystemInfos(searchPattern).Select(t => new DefaultFileSystemInfo(t)).Cast<IFileSystemInfo>().ToArray();
        }

        public IFileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption)
        {
            return _directoryInfo.GetFileSystemInfos(searchPattern, searchOption).Select(t => new DefaultFileSystemInfo(t)).Cast<IFileSystemInfo>().ToArray();
        }

        public IFileSystemInfo[] GetFileSystemInfos()
        {
            return _directoryInfo.GetFileSystemInfos().Select(t => new DefaultFileSystemInfo(t)).Cast<IFileSystemInfo>().ToArray();
        }

        public IDirectoryInfo[] GetDirectories(string searchPattern)
        {
            return _directoryInfo.GetDirectories(searchPattern).Select(t => new DefaultDirectoryInfo(t)).Cast<IDirectoryInfo>().ToArray();            
        }

        public IDirectoryInfo[] GetDirectories(string searchPattern, SearchOption searchOption)
        {
            return _directoryInfo.GetDirectories(searchPattern, searchOption).Select(t => new DefaultDirectoryInfo(t)).Cast<IDirectoryInfo>().ToArray();
        }

        public IEnumerable<IDirectoryInfo> EnumerateDirectories()
        {
            return _directoryInfo.EnumerateDirectories().Select(t => new DefaultDirectoryInfo(t));
        }

        public IEnumerable<IDirectoryInfo> EnumerateDirectories(string searchPattern)
        {
            return _directoryInfo.EnumerateDirectories(searchPattern).Select(t => new DefaultDirectoryInfo(t));
        }

        public IEnumerable<IDirectoryInfo> EnumerateDirectories(string searchPattern, SearchOption searchOption)
        {
            return _directoryInfo.EnumerateDirectories(searchPattern, searchOption).Select(t => new DefaultDirectoryInfo(t));
        }

        public IEnumerable<IFileInfo> EnumerateFiles()
        {
            return _directoryInfo.EnumerateFiles().Select(t => new DefaultFileInfo(t));
        }

        public IEnumerable<IFileInfo> EnumerateFiles(string searchPattern)
        {
            return _directoryInfo.EnumerateFiles(searchPattern).Select(t => new DefaultFileInfo(t));
        }

        public IEnumerable<IFileInfo> EnumerateFiles(string searchPattern, SearchOption searchOption)
        {
            return _directoryInfo.EnumerateFiles(searchPattern, searchOption).Select(t => new DefaultFileInfo(t));
        }

        public IEnumerable<IFileSystemInfo> EnumerateFileSystemInfos()
        {
            return _directoryInfo.EnumerateFileSystemInfos().Select(t => new DefaultFileSystemInfo(t));
        }

        public IEnumerable<IFileSystemInfo> EnumerateFileSystemInfos(string searchPattern)
        {
            return _directoryInfo.EnumerateFileSystemInfos(searchPattern).Select(t => new DefaultFileSystemInfo(t));
        }

        public IEnumerable<IFileSystemInfo> EnumerateFileSystemInfos(string searchPattern, SearchOption searchOption)
        {
            return _directoryInfo.EnumerateFileSystemInfos(searchPattern, searchOption).Select(t => new DefaultFileSystemInfo(t));
        }

        public void MoveTo(string destDirName)
        {
            _directoryInfo.MoveTo(destDirName);
        }

        public void Delete(bool recursive)
        {
            _directoryInfo.Delete(recursive);
        }

        public IDirectoryInfo Parent
        {
            get { return new DefaultDirectoryInfo(_directoryInfo.Parent); }
        }

        public IDirectoryInfo Root
        {
            get { return new DefaultDirectoryInfo(_directoryInfo.Root);}
        }
    }
}